from typing import *
from math import inf


class Solution:
    def maximumTripletValue(self, nums: List[int]) -> int:
        mn, mx = inf, -inf
        dmn, dmx = inf, -inf
        ans = 0
        for i, num in enumerate(nums):
            if i > 1:
                ans = max(ans, num * dmn, num * dmx)
            if i > 0:
                dmn, dmx = min(dmn, mn - num), max(dmx, mx - num)
            mn, mx = min(mn, num), max(mx, num)
        return ans
